<!-- 登录首页 -->
<template>
  <div class="app-container login-container">
    <el-form ref="form" :model="form" :rules="rules" class="form">
      <el-form-item>
        <h3>login</h3>
      </el-form-item>
      <el-form-item prop="username">
        <el-input v-model="form.username" >
          <i slot="prefix" class="el-icon-user"></i>
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password" v-model="form.password" @keyup.enter.native="login">
          <i slot="prefix" class="el-icon-lock"></i>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="login">login</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import '@/mock/user.js';
  export default {
    name: "index",
    data() {
      return {
        form: {
          username: '',
          password: ''
        },
        rules: {
          username: [
            { required: true, message: '请输入账号', trigger: 'change' }
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'change' }
          ]
        }
      }
    },
    methods: {
      login() {
        this.$refs.form.validate((valid) => {
          if (valid) {
            this.$http.post('login', this.form).then(res => {
              if ($isSuccess(res)) {
                sessionStorage.setItem('token', res.token);
                this.$router.push('/home')
              }
            })
          }
        })
      }
    }
  }
</script>

<style scoped lang="scss">
.login-container{
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #2d3a4b;
  color: #fff;
  .form{
    width: 500px;
    /deep/ .el-input__inner{
      background: #283443;
      color: #fff;
    }
  }
}

</style>
